package com.star.springai.chat.service;

import java.util.List;

import org.springframework.ai.document.Document;
import org.springframework.ai.reader.tika.TikaDocumentReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

@Component
public class MyTikaDocumentReader {

    private final Resource resource;

    MyTikaDocumentReader(@Value("classpath:/springai.pdf")
                         Resource resource) {
        this.resource = resource;
    }

    public List<Document> loadText() {
        TikaDocumentReader tikaDocumentReader = new TikaDocumentReader(resource);
        return tikaDocumentReader.read();
    }

    /**
     * 从指定文件路径读取文档
     */
    public List<Document> loadText(String filePath) {
        TikaDocumentReader tikaDocumentReader = new TikaDocumentReader(filePath);
        return tikaDocumentReader.read();
    }

    /**
     * 从Resource读取文档
     */
    public List<Document> loadText(Resource resource) {
        TikaDocumentReader tikaDocumentReader = new TikaDocumentReader(resource);
        return tikaDocumentReader.read();
    }
}